import Sequelize from 'sequelize'
import db from '../database'

const MenuInfo = db.define('menu_info',{
	id:{
		type: Sequelize.INTEGER,
        autoIncrement:true,
        allowNull: false
	},
    role:{
    	type:Sequelize.STRING,
    	primaryKey:true,
    	allowNull: false
    },
    menu:{
        type:Sequelize.STRING,
        allowNull: false
    }
},{
	freezeTableName:false,
	tableName:'menu_info',
	updatedAt:'update_time',
    createdAt:'create_time'
});

class MenuModel {
	add(record){
		return MenuInfo.create(record);
	}

	update(record){
		return MenuInfo.update(record,{
			where:{
				id:record.id
			}
		})
	}

	delete(id){
		return MenuInfo.destroy({
			where:{
				id:id
			}
		})
	}

	findById(id){
		return MenuInfo.findById(id);
	}
}

module.exports = new MenuModel();